package com.cdyx.outsideprescription.util;
/**
 * 应用统一返回结果数据封装类
 */
public class AppResponse<T> {
    private Integer resultCode;
    private String message;
    private Boolean success;
    private T data;

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 快速响应成功
     * @param data
     * @return
     */
    public static<T> AppResponse<T> ok(T data){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 0
        resp.setResultCode(ResponseCodeEnum.SUCCESS.getCode());
        // 对应枚举类中的 "操作成功"
        resp.setMessage(ResponseCodeEnum.SUCCESS.getMsg());
        resp.setSuccess(true);
        resp.setData(data);
        return resp;
    }
    public static<T> AppResponse<T> ok(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 0
        resp.setResultCode(ResponseCodeEnum.SUCCESS.getCode());
        // 对应枚举类中的 "操作成功"
        resp.setMessage(ResponseCodeEnum.SUCCESS.getMsg());
        resp.setSuccess(true);
        return resp;
    }
    /**
     * 成功
     * @param <T>
     * @return
     */
    public static<T> AppResponse<T> ok_save(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 0
        resp.setResultCode(ResponseCodeEnum.SUCCESS_SAVE.getCode());
        // 对应枚举类中的 "操作成功"
        resp.setMessage(ResponseCodeEnum.SUCCESS_SAVE.getMsg());
        resp.setSuccess(true);
        return resp;
    }

    /**
     * 快速响应失败
     */
    public static<T> AppResponse<T> fail(T data){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(ResponseCodeEnum.FAIL.getMsg());
        resp.setSuccess(false);
        resp.setData(data);
        return resp;
    }
    /**
     * 快速响应失败
     */
    public static<T> AppResponse<T> fail(String msg){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(msg);
        resp.setSuccess(false);
        resp.setData(null);
        return resp;
    }
    public static<T> AppResponse<T> fail(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(ResponseCodeEnum.FAIL.getMsg());
        resp.setSuccess(false);
        return resp;
    }

    /**
     * 快速响应失败
     */
    public static<T> AppResponse<T> fail_diagSave(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL_DIAGSAVE.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(ResponseCodeEnum.FAIL_DIAGSAVE.getMsg());
        resp.setSuccess(false);
        return resp;
    }
    public static<T> AppResponse<T> fail_recipeSave(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL_RECIPESAVE.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(ResponseCodeEnum.FAIL_RECIPESAVE.getMsg());
        resp.setSuccess(false);
        return resp;
    }
    public static<T> AppResponse<T> fail_Save(){
        AppResponse<T> resp = new AppResponse<T>();
        // 对应枚举类中的 1
        resp.setResultCode(ResponseCodeEnum.FAIL_RECIPESAVE.getCode());
        // 对应枚举类中的 "服务器异常"
        resp.setMessage(ResponseCodeEnum.FAIL_RECIPESAVE.getMsg());
        resp.setSuccess(false);
        return resp;
    }
}
